package models

import (
	"github.com/astaxie/beego/orm"
)

type ProjectScene struct {
	Id        int64 `orm:"pk;auto"`  // 项目ID
	ProjectId int64 `orm:"size(11)"` // 项目ID
	SceneId   int64 `orm:"size(11)"` // 场景ID
}

// 获取模型名称
// 获取模型表名
func (m *ProjectScene) TableName() string {
	return "project_scene"
}

// 获取全部用户
func (m *ProjectScene) GetAllUser() []*ProjectScene {
	info := ProjectScene{}
	list := make([]*ProjectScene, 0)
	_, _ = info.Query().All(&list)
	return list
}

// 查询方法
func (m *ProjectScene) Query() orm.QuerySeter {
	return orm.NewOrm().QueryTable(m)
}

// 添加用户
func (m *ProjectScene) Insert() error {
	_, err := orm.NewOrm().Insert(m)
	return err
}

// 删除用户
func (m *ProjectScene) Delete() error {
	_, err := orm.NewOrm().Delete(m)
	return err
}

// 修改用户信息
func (m *ProjectScene) Update(fields ...string) error {
	_, err := orm.NewOrm().Update(m, fields...)
	return err
}
func (m *ProjectScene) Read(fields ...string) (int64, error) {
	if err := orm.NewOrm().Read(m, fields...); err != nil {
		return 0, err
	}
	return m.Id, nil
}

// 通过ID查询单个用户信息
func (m *ProjectScene) GetProjectByProjectId(projectId int64) ([]*ProjectScene, error) {
	list := make([]*ProjectScene, 0)
	_, err := orm.NewOrm().QueryTable("tb_project_scene").RelatedSel("tb_project_libs").All(&list)
	return list, err
}
